﻿using LeastSquares.Function;

namespace LeastSquares
{
    internal class Program
    {
        /// <summary>
        /// 最小二乘法预测GDP
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //从数据文件中读取数据
            var model = new Model();
            //获取和设置当前目录（即该进程从中启动的目录）的完全限定路径。
            model.X = ReadNumberInTxt.ReadListFromText($@"{System.Environment.CurrentDirectory}\Data\Year.txt");
            model.Y = ReadNumberInTxt.ReadListFromText($@"{System.Environment.CurrentDirectory}\Data\GDP.txt");
            //计算参数a,b.
            model.Compute();
            Console.WriteLine("预测的年份为：");
            int year =Convert.ToInt32((Console.ReadLine()));                                           
            //预测
            var gdp = model.Forecast(year);
            Console.WriteLine($"预测{year}年的GDP为：{gdp:##.##}");
            Console.ReadKey();              
        }
    }
}